package LeetCode;

public class LC_203_RemoveLinkedListElements {

    public static void main(String[] args) {

    }

    static class Solution {

        public ListNode removeElements(ListNode head, int val) {
            if (head == null)
                return null;
            ListNode correct = new ListNode(0);
            correct.next = head;
            ListNode pre = correct;
            ListNode cur = correct.next;
            while (cur.next != null) {
                if (cur.val == val) {
                    pre.next = cur.next;
                } else {
                    pre = pre.next;
                }
                cur = cur.next;
            }
            if (cur.val == val)
                pre.next = null;
            return correct.next;
        }

    }
}